package Java7_Concurrency_Cookbook.thread_synchronized_helper.semaphore;

/**
 * 信号量, 用来保护一个或多个资源的共享访问<br/>
 * 如果线程要访问一个共享资源, 它必须先获得信号量.<br/>
 * 当线程使用完某个共享资源时, 信号量必须被释放<br/>
 */
public class Main {
    public static void main(String[] args) {
        PrintQueue printQueue = new PrintQueue();
        Thread[] threads = new Thread[10];
        for (int i = 0; i < 10; i++) {
            threads[i] = new Thread(new Job(printQueue), "Thread" + i);
        }
        for (int i = 0; i < 10; i++) {
            threads[i].start();
        }
    }
}
